<?php

FLEA::loadClass('Controller_Public');

class Controller_Admin extends Controller_Public
{
	function Controller_Admin()
    {
        
	}
	
	function actionIndex()
	{
		$smarty = &$this->_getView();		
		$smarty->display('admin_login.html');
	}

	
	function actionLogin()
	{
		$uname = $_POST['user_login'];		
		$upass = $_POST['user_pass'];
		
		$usersManager = &get_singleton('Model_UserManager');
		
		// 验证用户名和密码是否正确
		$user = $usersManager->findByUsername($uname);
		if (!$user || !$usersManager->checkPassword($upass, $user[$usersManager->passwordField])) {
			echo "Username invalid or password mismatch.";			
			exit;
		}

		// 获取用户角色信息
		$roles = $usersManager->fetchRoles($user);
		$rbac =& get_singleton('FLEA_Com_RBAC');
		
		$sessionUser = array(
			'USERID' => $user[$usersManager->primaryKey],
			'USERNAME' => $user[$usersManager->usernameField],
		);

		// 将用户ID、用户名和角色信息保存到 session
		$rbac->setUser($sessionUser, $roles);

		// 登录成功
		redirect(url('admin','manager'));

	}

	function actionLogout()
	{
		$rbac =& get_singleton('FLEA_Com_RBAC');
		$rbac->clearUser();
		redirect(url('admin','index'));
	}

	function actionManager()
	{

		$smarty = &$this->_getView();		
		$smarty->display($this->getTemplates());
	}

	function actionArtists()
	{
		$smarty = &$this->_getView();
		
		$smarty->display('admin_manager.html');
	}

	function actionAlbums()
	{
		$smarty = &$this->_getView();
		
		$smarty->display('admin_manager.html');
	}

	function actionLabels()
	{
		$smarty = &$this->_getView();
		
		$smarty->display('admin_manager.html');
	}


} 